package com.my.screenadapter.MyRecyclerHeader.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.my.screenadapter.Model.Person;
import com.my.screenadapter.R;

/**
 * Created by 张英杰 on 2016/11/15.
 * baseadapter没有header
 *
 *
 */
public class SonRvNormalAdapter extends BaseAdapter {
    public SonRvNormalAdapter(Context context) {
        super(context);
    }

    @Override
    protected ItemViewHolder getBaseViewHolder(View view) {

        return new MyHolder(view);
    }


    @Override
    public View initView() {
        return View.inflate(context, R.layout.item_list, null);
    }

    class MyHolder extends ItemViewHolder {
        TextView tv;
        EditText et;
        ImageView iv;

        public MyHolder(View itemView) {
            super(itemView);
        }

        /**
         * todo{@link BaseAdapter#onBindViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder, int) }
         * 中settag
         */
        @Override
        protected void createView() {
            tv = (TextView) holderView.findViewById(R.id.id_item_list_title);
            et = (EditText) holderView.findViewById(R.id.item_et);
            iv = (ImageView) holderView.findViewById(R.id.item_iv);

            et.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO: 2019-11-21
                    final int position = (int) itemView.getTag();
                    Person p = (Person) datas.get(position);
                    p.setName(String.valueOf(s).trim());
                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });
        }

        @Override
        protected void bindData(Object o) {
            Person p = (Person) o;
            tv.setText(p.getAge() + "-" + p.getGender() + "-" + p.getName());
            et.setText(p.getName());

        }
    }
}
